﻿
using CSharpLibs.Annotations;

namespace System.IO
{
	[Builtin]
	public abstract class TextReader : Object, IDisposable
	{
		public virtual void Close()
		{ ;}

		public void Dispose()
		{ this.Close(); }

		public virtual int Peek()
		{ return -1; }

		public virtual int Read()
		{ return -1; }

		public virtual int Read(char[] buffer, int index, int count)
		{
			int num = 0;
			do
			{
				int num2 = this.Read();
				if(num2 == -1)
				{
					return num;
				}
				buffer[index + num++] = (char)num2;
			}
			while(num < count);
			return num;
		}

		public virtual string ReadLine()
		{
			Text.StringBuilder builder = new Text.StringBuilder();
			while(true)
			{
				int num = this.Read();
				switch(num)
				{
					case -1:
						if(builder.Length > 0)
							return builder.ToString();
						return null;

					case 13:
					case 10:
						if((num == 13) && (this.Peek() == 10))
							this.Read();
						return builder.ToString();
				}
				builder.Append((char)num);
			}
		}

		public virtual string ReadToEnd()
		{
			int num;
			char[] buffer = new char[0x1000];
			Text.StringBuilder builder = new Text.StringBuilder();
			while((num = this.Read(buffer, 0, buffer.Length)) != 0)
			{
				builder.Append(buffer, num);
			}
			return builder.ToString();
		}
	}
}
